BEGIN TRY
    BEGIN DISTRIBUTED TRANSACTION;
    
    -- 跨服务器操作
    UPDATE ServerA.DB.dbo.Table1 SET Column1 = 1;
    UPDATE ServerB.DB.dbo.Table2 SET Column2 = 2;

    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    IF (XACT_STATE()) = -1  -- 事务处于可回滚状态
        ROLLBACK TRANSACTION;
    
    DECLARE @ErrorMsg NVARCHAR(4000) = ERROR_MESSAGE();
    RAISERROR('事务失败: %s', 16, 1, @ErrorMsg);
END CATCH;
